/*
 * Proja - project management software
 * Copyright (C) 2012  Oleg Kasian
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

package org.proja.core.entity;

import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 *
 * @author oleg
 */
@Entity
@Table(name = "ISSUE_MEMBERS")
public class IssueMember extends AbstractEntity {

    @Id
    @SequenceGenerator(name = "IssueMemberSeq", sequenceName = "ISSUE_MEMBERS_SEQ")
    @GeneratedValue(generator = "IssueMemberSeq")
    @Column(name = "ID", updatable = false)
    private Long id;

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "USER_ID", nullable = false)
    private User user;

    @ManyToMany(cascade = CascadeType.DETACH)
    @JoinTable(name = "IMEMBERS_IMEMBER_ROLES",
            joinColumns = { @JoinColumn(name = "MEMBER_ID") },
            inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") })
    private Set<IssueMemberRole> roles;

    @ManyToOne(cascade = CascadeType.DETACH)
    @JoinColumn(name = "ISSUE_ID")
    private Issue issue;

    public Long getId() {
        return id;
    }

    public void setId(final Long id) {
        this.id = id;
    }

    public User getUser() {
        return user;
    }

    public void setUser(final User user) {
        this.user = user;
    }

    public Set<IssueMemberRole> getRoles() {
        return roles;
    }

    public void setRoles(final Set<IssueMemberRole> roles) {
        this.roles = roles;
    }

    public Issue getIssue() {
        return issue;
    }

    public void setIssue(final Issue issue) {
        this.issue = issue;
    }

}
